const permi = {
	bind(el, binding, vnode) {
		const { value } = binding
		// vnode.context.$nextTick(() => {
		const permissions = vnode.context.$route.meta.permi
		if (permissions && permissions.length > 0) {
			if (value && value.length > 0) {
				let hasPer = permissions.some(per => {
					return value.includes(per)
				})
				if (!hasPer) {
					// 删除按钮
					// el.parentNode.removeChild(el)
					el.remove()
				}
			}
		}
		// })
	},
	// bind(el, binding, vnode) {
	// 	console.log('===元素===' + el.innerText + '===inserted====')
	// },
	componentUpdated(el, binding, vnode) {
		vnode.context.$nextTick(() => {
			const { value } = binding
			const permissions = vnode.context.$route.meta.permi
			if (permissions && permissions.length > 0) {
				if (value && value.length > 0) {
					let hasPer = permissions.some(per => {
						return value.includes(per)
					})
					if (!hasPer) {
						// 删除按钮
						// el.parentNode.removeChild(el)
						el.remove()
					}
				}
			}
		})
	},
}

const install = function(Vue) {
	Vue.directive('hasPerm', permi)
}
export default install
